package org.sample.dm.datatype.core;

import liquibase.change.core.LoadDataChange;
import liquibase.database.Database;
import liquibase.database.core.SnowflakeDatabase;
import liquibase.datatype.DataTypeInfo;
import liquibase.datatype.DatabaseDataType;
import liquibase.datatype.LiquibaseDataType;
import liquibase.datatype.core.BooleanType;
import org.sample.dm.database.core.DmDatabase;

@DataTypeInfo(
        name = "boolean",
        aliases = {"java.sql.Types.BOOLEAN", "java.lang.Boolean", "bit", "bool"},
        minParameters = 0,
        maxParameters = 0,
        priority = LiquibaseDataType.PRIORITY_DATABASE
)
public class DmBooleanType extends BooleanType {
    @Override
    public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() {
        return LoadDataChange.LOAD_DATA_TYPE.BOOLEAN;
    }

    public DatabaseDataType toDatabaseDataType(Database database){
        if (database instanceof DmDatabase){
            return new DatabaseDataType("BIT");
        }
        return super.toDatabaseDataType(database);
    }

    @Override
    public boolean supports(Database database) {
        return database instanceof DmDatabase;
    }

    @Override
    protected boolean isNumericBoolean(Database database) {
        if (database instanceof DmDatabase){
            return true;
        }
        return super.isNumericBoolean(database);
    }
}
